package com.yunhe.tianhe.rentcars.service.system.impl;

import com.yunhe.tianhe.rentcars.dao.system.SysDictDao;
import com.yunhe.tianhe.rentcars.dto.TreeNode;
import com.yunhe.tianhe.rentcars.entity.system.SysDict;
import com.yunhe.tianhe.rentcars.service.system.SysDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * # @Author: 贾波
 * # @Time: 2017-11-25-上午 11:14
 * # Description:
 */
@Service
public class SysDictServiceImpl implements SysDictService {
    @Autowired
    private SysDictDao sysDictDao;
    public Long save(SysDict sysDict) {
        sysDictDao.save(sysDict);
        return sysDict.getId();
    }

    @Override
    public Long update(SysDict sysDict) {
        return sysDictDao.update(sysDict);
    }

    @Override
    public SysDict findOne(String name) {
        return sysDictDao.findOne(name);
    }
    @Override
    public List<TreeNode> findTreeNodes(SysDict sysDict) {
        ArrayList<TreeNode> treeNodes = new ArrayList<>();
        List<SysDict> allSysDict = sysDictDao.findList();
        if (null!=allSysDict){
            for (SysDict s:allSysDict){
                TreeNode treeNode = new TreeNode(s.getId(), s.getfId(), s.getName());
                treeNodes.add(treeNode);
            }
        }
        return treeNodes;
    }
}
